package com.yk.framework.gui.wf.ui.form;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JTextField;

import com.yk.framework.gui.ctrl.YKDialog;
import com.yk.framework.gui.wf.Contants;

/**
 * This code was edited or generated using CloudGarden's Jigloo
 * SWT/Swing GUI Builder, which is free for non-commercial
 * use. If Jigloo is being used commercially (ie, by a corporation,
 * company or business for any purpose whatever) then you
 * should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details.
 * Use of Jigloo implies acceptance of these licensing terms.
 * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
 * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
 * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
/**
 * @author lifetime
 * 
 */
@SuppressWarnings("serial")
public class ConditionForm extends AbstractTemplateForm {
	private JComboBox agreeItems;
	private JTextField ctrlScript;
	private JButton btnCancel;
	private JButton btnOK;
	private JLabel jLabel2;
	private JLabel jLabel1;

	public ConditionForm(YKDialog ownerFrame, JLabel lbl) {
		super(ownerFrame, lbl);
		this.ownerFrame = ownerFrame;
		this.lbl = lbl;
		initGUI();
	}

	public void loadFields() {
		agreeItems.setSelectedItem(editData.getString("item"));
		ctrlScript.setText(editData.getString("script"));
	}

	public void storeFields() {
		editData.put("item", agreeItems.getSelectedItem().toString());
		editData.put("script", ctrlScript.getText());
	}

	private void initGUI() {
		try {
			this.setPreferredSize(new java.awt.Dimension(509, 436));
			this.setLayout(null);
			{
				ComboBoxModel agreeItemsModel = new DefaultComboBoxModel(new String[] { Contants.WF_System_AgreeText, Contants.WF_System_NoAgreeText });
				agreeItems = new JComboBox();
				agreeItems.addKeyListener(ownerFrame);
				this.add(agreeItems);
				agreeItems.setModel(agreeItemsModel);
				agreeItems.setBounds(108, 17, 74, 21);
			}
			{
				jLabel1 = new JLabel();
				jLabel1.addKeyListener(ownerFrame);
				this.add(jLabel1);
				jLabel1.setText("\u5176\u4ed6\u63a7\u5236\u811a\u672c");
				jLabel1.setBounds(10, 64, 94, 15);
			}
			{
				ctrlScript = new JTextField();
				ctrlScript.addKeyListener(ownerFrame);
				this.add(ctrlScript);
				ctrlScript.setBounds(108, 61, 377, 21);
			}
			{
				jLabel2 = new JLabel();
				jLabel2.addKeyListener(ownerFrame);
				this.add(jLabel2);
				jLabel2.setText("\u8df3\u8f6c\u9009\u9879");
				jLabel2.setBounds(10, 20, 76, 15);
			}
			{
				btnOK = new JButton();
				btnOK.addKeyListener(ownerFrame);
				btnOK.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						storeFields();
						lbl.putClientProperty("editData", editData);
						lbl.setText(editData.getString("item"));
						ownerFrame.setVisible(false);
						setCancel(false);
					}
				});
				this.add(btnOK);
				btnOK.setText("\u786e\u5b9a");
				btnOK.setBounds(331, 401, 80, 24);
			}
			{
				btnCancel = new JButton();
				btnCancel.addKeyListener(ownerFrame);
				btnCancel.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						ownerFrame.setVisible(false);
						setCancel(true);
					}
				});
				this.add(btnCancel);
				btnCancel.setText("\u53d6\u6d88");
				btnCancel.setBounds(422, 401, 76, 24);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
